package Gameplay.Enemy;

import ADTs.PointADT;
import Gameplay.Level;
import Gameplay.Player;
import Gameplay.Projectile.Projectile;
import Project.Main;

public class AI5 extends AI{

	private long lastMove;
	private long moveCooldown;
	private int tempCoolDown;
	private long lastFired2;

	public AI5(){
		super();
		this.lastMove = 0;
		this.moveCooldown = 500;
		this.cooldown = 800;
		this.lastFired = 0;
		tempCoolDown = 80;
		lastFired2 = 0;

	}

	public boolean move(Enemy e){
		return this.moveUpAndDown(e);

	}
	public boolean moveUpAndDown(Enemy e) {
		if(this.moveCooldown < (System.currentTimeMillis() - lastMove) ){
			double pick = Math.random();
			PointADT aPoint = null;
			if(pick > .5)
				aPoint= new PointADT(0, 5.0 - 1);
			else{
				aPoint= new PointADT(0, -5.0 + 1);
			}
			e.setAcceleration(aPoint);
			e.getAcceleration().scale(10);
			lastMove = System.currentTimeMillis();
			return true;
		}
		return false;
	}
	@Override
	public void attack(Enemy e) {
		Player p = ((Level)Main.getCurrentUI()).getPlayer();
		PointADT horiShoot = new PointADT(e.getLocation().copy().getX() + 900, e.getLocation().copy().getY());
		PointADT dest = PointADT.addPoints(horiShoot, new PointADT(-e.getLocation().getX(),-e.getLocation().getY()));
		PointADT verticalShootup = new PointADT(e.getLocation().copy().getX(), e.getLocation().copy().getY() - 100);
		PointADT verticalShootdown = new PointADT(e.getLocation().copy().getX(), e.getLocation().copy().getY() + 100);
		PointADT destUp = PointADT.addPoints(verticalShootup, new PointADT(-e.getLocation().getX(),-e.getLocation().getY()));
		PointADT destDown = PointADT.addPoints(verticalShootdown, new PointADT(-e.getLocation().getX(),-e.getLocation().getY()));
		dest.setY(-dest.getY());
		if(lastFired + cooldown < System.currentTimeMillis()) {
			dest.setY(-dest.getY());
			((Level) Main.getCurrentUI()).addToState(new Projectile(dest, e.getLocation().copy(), false));
			lastFired = System.currentTimeMillis();
		}
		if(p.getLocation().copy().getX() < e.getLocation().getX() + 50){
			if(lastFired2 + tempCoolDown < System.currentTimeMillis()) {
				destUp.setY(-destUp.getY());
				((Level) Main.getCurrentUI()).addToState(new Projectile(destUp, e.getLocation().copy(), false));
				destDown.setY(-destDown.getY());
				((Level) Main.getCurrentUI()).addToState(new Projectile(destDown, e.getLocation().copy(), false));
				lastFired2 = System.currentTimeMillis();
			}
		}
	}
}
